package org.example.top41_80;

import java.util.Queue;
import java.util.Stack;

public class MyQueue {
    //void push(int x) 将元素 x 推到队列的末尾
    //int pop() 从队列的开头移除并返回元素
    //int peek() 返回队列开头的元素
    //boolean empty() 如果队列为空，返回 true ；否则，返回 false
    Stack<Integer> in;
    Stack<Integer> out;

    public MyQueue() {
        in = new Stack<>();
        out = new Stack<>();
    }

    public void push(int x) {
        in.push(x);
    }

    public int pop() {
        dumpOut();
        return out.pop();
    }
    public boolean empty(){
        return in.isEmpty()&&out.isEmpty();
    }

    public int peek(){
        dumpOut();
        return out.peek();
    }

    private void dumpOut(){
        if(!out.isEmpty()){
            return ;
        }
        while (!in.isEmpty()){
            out.push(in.pop());
        }
    }
}
